CFLAGS = -O0 -g -Wall -Werror -fPIC

OBJ = trace.o

TRACE_LIB_STATIC = trace.a
TRACE_LIB = trace.so

LLVM_OBJ = $(shell pwd)/../../../../llvm-obj/
LLVM_STUB = $(LLVM_OBJ)/Debug/lib/trace-sync-events-stub.so

all: $(LLVM_STUB)

$(TRACE_LIB_STATIC): $(OBJ)
	ar rcs $@ $<

$(TRACE_LIB): $(OBJ)
	gcc $(CFLAGS) -shared -Wl,-soname,$@ -o $@ $<

%.o: %.c
	gcc $(CFLAGS) -o $@ -c $<

$(LLVM_STUB):
	make -C stub

test: test.c $(LLVM_STUB) $(TRACE_LIB)

.PHONE: clean clean-test

clean: clean-test
	-rm -f $(OBJ) $(TRACE_LIB) *~

clean-test:
	rm -rf *.o *.s *.a test ./stub/Debug/ $(LLVM_OBJ)/Debug/lib/trace-sync-events-stub*
